package dr.item.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.oreilly.servlet.MultipartRequest;

import dr.controller.Action;
import dr.item.dao.ItemDAO;
import dr.item.domain.Item;
import dr.util.FileUtil;

public class UpdateProAction implements Action {

	public String execute(HttpServletRequest request, 
			HttpServletResponse response) throws Throwable {

		MultipartRequest multi = FileUtil.createFile(request);
		request.setCharacterEncoding("euc-kr");
		String pageNum = request.getParameter("pageNum");

        ItemDAO dbPro = ItemDAO.getInstance();
        int tmp_no = dbPro.makeFileNo();
        
		Item article = new Item();
		article.setItem_num(Integer.parseInt(request.getParameter("item_num")));
		article.setItem_kind(multi.getParameter("item_kind"));
		article.setItem_name(multi.getParameter("item_name"));
        article.setItem_passwd(multi.getParameter("item_passwd"));
        article.setItem_content(multi.getParameter("item_content"));
		article.setItem_img(FileUtil.rename(multi.getFilesystemName("item_img"), tmp_no, "item_img"));
        
        int check = dbPro.updateArticle(article);
        System.out.println("aaaaaaaaaaa"+request.getParameter("item_passwd"));
        request.setAttribute("pageNum", new Integer(pageNum));
        request.setAttribute("check", new Integer(check));
        
		return "/item/updatePro.jsp";
	}

}
